package com.icoding.fw.utils;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

public class HqlQuery {

	private Query query;
	private Session session;

	public HqlQuery() {
		super();
	}

	public HqlQuery(Session session) {
		setSession(session);
	}

	public HqlQuery(Query query, Session session) {
		super();
		this.query = query;
		this.session = session;
	}

	public void setQuery(Query query) {
		this.query = query;
	}

	public Session getSession() {
		return session;
	}

	public void setSession(Session session) {
		this.session = session;
	}

	/**
	 * @param sql
	 * @return
	 */
	public Query creatHqlQuery(String sql) {
		return query;
	}

	/**
	 * @param position
	 * @param val
	 * @return
	 */
	public Query setParameter(int position, Object val) {
		return query.setParameter(position, val);
	}

	/**
	 * @param name
	 * @param val
	 * @return
	 */
	public Query setParameter(String name, Object val) {
		return query.setParameter(name, val);
	}

	/**
	 * @param position
	 * @param val
	 * @param type
	 * @return
	 */
	public Query setParameter(int position, Object val,
			org.hibernate.type.Type type) {
		return query.setParameter(position, val, type);
	}

	/**
	 * @param name
	 * @param val
	 * @param type
	 * @return
	 */
	public Query setParameter(String name, Object val,
			org.hibernate.type.Type type) {
		return query.setParameter(name, val, type);
	}

	@SuppressWarnings("unchecked")
	public <T> List<T> list() {
		return query.list();
	}

	// Return query of sql
	public String getQuery() {
		return query.getQueryString();
	}

	public int executeUpdate() {
		return query.executeUpdate();
	}
}
